﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 八皇后
{
    public class Solution
    {
        public int n = 8;
        public int[] index;

        public List<int[]> result = new();

        public Solution(int n)
        {
            this.n = n;
            this.index = new int[n];
            for(int i = 0; i < n; i++)
            {
                index[i] = -1;
            }
        }

        public void Dfs(int i)
        {
            for(int j = 0; j < n; j++)
            {
                if (Correct(i, j))
                {
                    index[i] = j;
                    if (i == n - 1)
                    {
                        result.Add((int[])index.Clone());
                    }
                    else
                    {
                        Dfs(i + 1);
                    }
                    index[i] = -1;
                }
            }
        }

        public bool Correct(int i,int position)
        {
            for(int j = 0; j < i; j++)
            {
                if (index[j] == position)
                {
                    return false;
                }
                if (Math.Abs(i - j) == Math.Abs(index[j] - position))
                {
                    return false;
                }
            }
            return true;
        }
    }
}
